package com.kim.smartring.activity.fragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.kim.smartring.R;

/**
 * 心率页
 * 
 */
public class HeartRateFragment extends BaseFragment {
	private ImageView img_menu;

	private LinearLayout ll_round;// 圆圈
	private TextView txv_msg;// 圆圈中间的文字
	private TextView txv_time;// 圆圈下面显示时间的文字

	private ImageView img_heart_base;// 心率标准
	private ListView listview;// 心率标准

	private Animation mAnimation;
	private TestHandler handler;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.heart_rate_layout, null);

		mAnimation = AnimationUtils.loadAnimation(getActivity(),
				R.anim.heart_rate);
		mAnimation.setInterpolator(new LinearInterpolator());

		img_menu = (ImageView) v.findViewById(R.id.img_menu);
		ll_round = (LinearLayout) v.findViewById(R.id.ll_round_turnt);
		img_heart_base = (ImageView) v.findViewById(R.id.img_heart_base);

		txv_msg = (TextView) v.findViewById(R.id.txv_msg);
		txv_time = (TextView) v.findViewById(R.id.txv_time);

		listview = (ListView) v.findViewById(R.id.listview);

		img_menu.setOnClickListener(this);
		ll_round.setOnClickListener(this);

		handler = new TestHandler();
		return v;
	}

	@Override
	public void onClick(View arg0) {

		switch (arg0.getId()) {
		case R.id.img_menu:
			showSlidingMenu();
			break;
		case R.id.ll_round_turnt:
			showAnimation();
			handler.sendEmptyMessageDelayed(0, 5000);
			break;

		default:
			break;
		}

	}

	private void showAnimation() {
		ll_round.setAnimation(mAnimation);
	}

	private void stopAnimation() {
		ll_round.clearAnimation();
		ll_round.setBackgroundResource(R.drawable.heart_round_default_selector);
	}

	class TestHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			stopAnimation();
		}
	}

}